import random

# 定义五行列表
elements = ["金", "木", "水", "火", "土"]

# 定义五行相生关系
generation_rules = {
    "金": "水",
    "水": "木",
    "木": "火",
    "火": "土",
    "土": "金"
}

# 定义五行相克关系
restraint_rules = {
    "金": "木",
    "木": "土",
    "土": "水",
    "水": "火",
    "火": "金"
}

# 显示五行选项
def show_elements():
    print("五行选项如下：")
    for i, element in enumerate(elements, start=1):
        print(f"{i}. {element}")

# 获取玩家选择
def get_player_choice():
    while True:
        try:
            choice = int(input("请输入你选择的五行序号 (1 - 5): "))
            if 1 <= choice <= 5:
                return elements[choice - 1]
            else:
                print("输入的序号无效，请输入 1 到 5 之间的数字。")
        except ValueError:
            print("输入无效，请输入一个有效的整数编号。")

# 判断胜负
def judge_result(player_choice, computer_choice):
    if player_choice == computer_choice:
        return "平局"
    elif restraint_rules[player_choice] == computer_choice:
        return "你赢了"
    else:
        return "你输了"

# 主游戏函数
def five_elements_game():
    print("欢迎来到五行生克游戏！")
    while True:
        show_elements()
        player_choice = get_player_choice()
        computer_choice = random.choice(elements)
        print(f"你选择了 {player_choice}，电脑选择了 {computer_choice}。")
        result = judge_result(player_choice, computer_choice)
        print(result)
        play_again = input("是否继续游戏？(y/n): ")
        if play_again.lower() != 'y':
            print("游戏结束，感谢参与！")
            break

if __name__ == "__main__":
    five_elements_game()